This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
library(velocyto.R)
载入需要的程辑包:Matrix
library(SeuratWrappers)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
library(Seurat)
载入程辑包:‘Seurat’
The following objects are masked from ‘package:SeuratWrappers’:
ALRAChooseKPlot, ExportToCellbrowser, ReadAlevin, RunALRA, StopCellbrowser
source("tianfengRwrappers.R")
载入需要的程辑包:dplyr
载入程辑包:‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
载入需要的程辑包:reticulate
载入需要的程辑包:tidyr
载入程辑包:‘tidyr’
The following objects are masked from ‘package:Matrix’:
expand, pack, unpack
载入程辑包:‘MySeuratWrappers’
The following objects are masked from ‘package:Seurat’:
DimPlot, DoHeatmap, LabelClusters, RidgePlot, VlnPlot
载入程辑包:‘cowplot’
The following object is masked from ‘package:ggpubr’:
get_legend
载入需要的程辑包:viridisLite
载入程辑包:‘reshape2’
The following object is masked from ‘package:tidyr’:
smiths
NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
Registered S3 method overwritten by 'enrichplot':
method from
fortify.enrichResult DOSE
clusterProfiler v3.14.3 For help: https://guangchuangyu.github.io/software/clusterProfiler
If you use clusterProfiler in published research, please cite:
Guangchuang Yu, Li-Gen Wang, Yanyan Han, Qing-Yu He. clusterProfiler: an R package for comparing biological themes among gene clusters. OMICS: A Journal of Integrative Biology. 2012, 16(5):284-287.
Registering fonts with R
载入程辑包:‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
载入需要的程辑包:Biobase
载入需要的程辑包:BiocGenerics
载入需要的程辑包:parallel
载入程辑包:‘BiocGenerics’
The following objects are masked from ‘package:parallel’:
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ, clusterExport, clusterMap, parApply,
parCapply, parLapply, parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from ‘package:dplyr’:
combine, intersect, setdiff, union
The following object is masked from ‘package:Matrix’:
which
The following objects are masked from ‘package:stats’:
IQR, mad, sd, var, xtabs
The following objects are masked from ‘package:base’:
anyDuplicated, append, as.data.frame, basename, cbind, colnames, dirname, do.call, duplicated,
eval, evalq, Filter, Find, get, grep, grepl, intersect, is.unsorted, lapply, Map, mapply, match,
mget, order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank, rbind, Reduce, rownames,
sapply, setdiff, sort, table, tapply, union, unique, unsplit, which, which.max, which.min
Welcome to Bioconductor
Vignettes contain introductory material; view with 'browseVignettes()'. To cite Bioconductor, see
'citation("Biobase")', and for packages 'citation("pkgname")'.
载入需要的程辑包:e1071
载入程辑包:‘widgetTools’
The following object is masked from ‘package:dplyr’:
funs
载入程辑包:‘DynDoc’
The following object is masked from ‘package:BiocGenerics’:
path
载入程辑包:‘DT’
The following object is masked from ‘package:Seurat’:
JS
载入需要的程辑包:S4Vectors
载入需要的程辑包:stats4
载入程辑包:‘S4Vectors’
The following object is masked from ‘package:plotly’:
rename
The following object is masked from ‘package:tidyr’:
expand
The following objects are masked from ‘package:dplyr’:
first, rename
The following object is masked from ‘package:Matrix’:
expand
The following object is masked from ‘package:base’:
expand.grid
载入需要的程辑包:IRanges
载入程辑包:‘IRanges’
The following object is masked from ‘package:plotly’:
slice
The following objects are masked from ‘package:dplyr’:
collapse, desc, slice
载入需要的程辑包:GenomicRanges
载入需要的程辑包:GenomeInfoDb
载入需要的程辑包:SummarizedExperiment
载入需要的程辑包:DelayedArray
载入需要的程辑包:matrixStats
载入程辑包:‘matrixStats’
The following objects are masked from ‘package:Biobase’:
anyMissing, rowMedians
The following object is masked from ‘package:dplyr’:
count
载入需要的程辑包:BiocParallel
载入程辑包:‘DelayedArray’
The following objects are masked from ‘package:matrixStats’:
colMaxs, colMins, colRanges, rowMaxs, rowMins, rowRanges
The following object is masked from ‘package:clusterProfiler’:
simplify
The following objects are masked from ‘package:base’:
aperm, apply, rowsum
载入程辑包:‘SummarizedExperiment’
The following object is masked from ‘package:Seurat’:
Assays
#首先需要取并集,然后使用已有的umap,在其上绘制速率图
velodata1 <- ReadVelocity(file ="./velo_data/CARconHEL.loom")
reading loom file via hdf5r...
velodata2 <- ReadVelocity(file ="./velo_data/CARconHEA0620.loom")
reading loom file via hdf5r...
velodata3 <- ReadVelocity(file ="./velo_data/CARconHEA0717.loom")
reading loom file via hdf5r...
#PA
# velodata1 <- ReadVelocity(file ="./velo_data/CARconDIS.loom")
# velodata2 <- ReadVelocity(file ="./velo_data/CARconDIS0620.loom")
# velodata3 <- ReadVelocity(file ="./velo_data/CARconDIS0717.loom")
#匹配两次的barcode
func <- function(s)
{
s <- strsplit(s,".*:",fixed = F)[[1]][2]
s <- strsplit(s,"x",fixed = T)[[1]]
s <- paste(s,"1",sep = "-")
return(s)
}
velodata1[["spliced"]]@Dimnames[[2]] = as.character(lapply(velodata1[["spliced"]]@Dimnames[[2]],func))
velodata1[["unspliced"]]@Dimnames[[2]] = as.character(lapply(velodata1[["unspliced"]]@Dimnames[[2]],func))
velodata1[["ambiguous"]]@Dimnames[[2]] = as.character(lapply(velodata1[["ambiguous"]]@Dimnames[[2]],func))
func <- function(s)
{
s <- strsplit(s,".*:",fixed = F)[[1]][2]
s <- strsplit(s,"x",fixed = T)[[1]]
s <- paste(s,"3",sep = "-")
return(s)
}
velodata2[["spliced"]]@Dimnames[[2]] = as.character(lapply(velodata2[["spliced"]]@Dimnames[[2]],func))
velodata2[["unspliced"]]@Dimnames[[2]] = as.character(lapply(velodata2[["unspliced"]]@Dimnames[[2]],func))
velodata2[["ambiguous"]]@Dimnames[[2]] = as.character(lapply(velodata2[["ambiguous"]]@Dimnames[[2]],func))
func <- function(s)
{
s <- strsplit(s,".*:",fixed = F)[[1]][2]
s <- strsplit(s,"x",fixed = T)[[1]]
s <- paste(s,"5",sep = "-")
return(s)
}
velodata3[["spliced"]]@Dimnames[[2]] = as.character(lapply(velodata3[["spliced"]]@Dimnames[[2]],func))
velodata3[["unspliced"]]@Dimnames[[2]] = as.character(lapply(velodata3[["unspliced"]]@Dimnames[[2]],func))
velodata3[["ambiguous"]]@Dimnames[[2]] = as.character(lapply(velodata3[["ambiguous"]]@Dimnames[[2]],func))
# CA_dataset2 <- readRDS("CA_dataset2.rds")
ds2_AC <- readRDS("ds2_AC.rds")
sp1_velo <- as.Seurat(x = velodata1)
|
| | 0%Warning: Non-unique features (rownames) present in the input matrix, making unique
|
|=================================== | 33%
|
|====================================================================== | 67%
|
|=========================================================================================================| 100%
sp2_velo <- as.Seurat(x = velodata2)
|
| | 0%Warning: Non-unique features (rownames) present in the input matrix, making unique
|
|=================================== | 33%
|
|====================================================================== | 67%
|
|=========================================================================================================| 100%
sp3_velo <- as.Seurat(x = velodata3)
|
| | 0%Warning: Non-unique features (rownames) present in the input matrix, making unique
|
|=================================== | 33%
|
|====================================================================== | 67%
|
|=========================================================================================================| 100%
merge_velo <- merge(sp1_velo, c(sp2_velo,sp3_velo))
merge_velo <- subset(merge_velo, cells = WhichCells(ds2_AC))
rm(sp1_velo)
rm(sp2_velo)
rm(sp3_velo)
rm(velodata1)
rm(velodata2)
rm(velodata3)
merge_velo <- readRDS("dataset2_PA_velo.RDS")
Loading required package: Seurat
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
# saveRDS(merge_velo,"dataset2_AC_velo.RDS")
# merge_velo <- readRDS("dataset2_AC_velo.RDS")
ident.colors <- colors_list[1:length(x = levels(x = merge_velo))]
names(x = ident.colors) <- levels(x = merge_velo)
cell.colors <- ident.colors[Idents(object = merge_velo)]
names(x = cell.colors) <- colnames(x = merge_velo)
png("velocity.png")
show.velocity.on.embedding.cor(emb = Embeddings(object = merge_velo, reduction = "umap"), vel = Tool(object = merge_velo, slot = "RunVelocity"), n = 200, scale = "sqrt", cell.colors = ac(x = cell.colors, alpha = 0.5),
cex = 0.8, arrow.scale = 3, show.grid.flow = TRUE, min.grid.cell.mass = 0.5, grid.n = 40, arrow.lwd = 1,
do.par = FALSE, cell.border.alpha = 0.1)
delta projections ... sqrt knn ... transition probs ... done
calculating arrows ... done
grid estimates ... grid.sd= 0.5051766 min.arrow.size= 0.01010353 max.grid.arrow.length= 0.04539128 done
dev.off()
null device
1
# plot <- tSNE.velocity.plot(vel = Tool(object = sp1_velo, slot = "RunVelocity"))
source("../vascular-analysis/seuratToAnnDataCombined.R")
h5ad_output <- "AC_SMC_velo.h5ad"
library(reticulate)
library(Matrix)
writeMM(t(merge_velo@assays$RNA@counts), file='combined.mtx')
NULL
writeMM(t(merge_velo@assays$spliced@counts), file='spliced.mtx')
NULL
writeMM(t(merge_velo@assays$unspliced@counts), file='unspliced.mtx')
NULL
write.csv(rownames(merge_velo@assays$spliced@counts), file = "genes.csv", row.names = FALSE)
write.csv(merge_velo@reductions$umap@cell.embeddings, file = "umap.csv", row.names = FALSE)
write.csv(merge_velo@reductions$pca@cell.embeddings, file = "pca.csv", row.names = FALSE)
write.csv(colnames(merge_velo@assays$spliced@counts), file = "cells.csv", row.names = FALSE)
write.csv(merge_velo@meta.data, file = "meta.csv", row.names = FALSE)
source_python('~/scRNAseq/vascular-analysis/build.py')
build(h5ad_output, pca = TRUE, umap = TRUE)
file.remove('combined.mtx')
[1] TRUE
file.remove('spliced.mtx')
[1] TRUE
file.remove('unspliced.mtx')
[1] TRUE
file.remove('genes.csv')
[1] TRUE
file.remove('cells.csv')
[1] TRUE
file.remove('umap.csv')
[1] TRUE
file.remove('pca.csv')
[1] TRUE
file.remove('meta.csv')
[1] TRUE
SMC_velo <- subset(merge_velo, idents = "SMC")
RunVelocity(object = SMC_velo, deltaT = 1, kCells = 25, fit.quantile = 0.02)
ident.colors <- colors_list[1:length(x = levels(x = SMC_velo))]
names(x = ident.colors) <- levels(x = SMC_velo)
cell.colors <- ident.colors[Idents(object = SMC_velo)]
names(x = cell.colors) <- colnames(x = SMC_velo)
png("SMC_velocity.png")
show.velocity.on.embedding.cor(emb = Embeddings(object = SMC_velo, reduction = "umap"), vel = Tool(object = SMC_velo, slot = "RunVelocity"), n = 200, scale = "sqrt", cell.colors = ac(x = cell.colors, alpha = 0.5),
cex = 0.8, arrow.scale = 3, show.grid.flow = TRUE, min.grid.cell.mass = 0.5, grid.n = 40, arrow.lwd = 1,
do.par = FALSE, cell.border.alpha = 0.1)
dev.off()
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.